package presentation;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;

import db.DbUtils;
import db.Picture;

public class DeleteCommentServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		Long imageId = Long.parseLong(request.getParameter("image"));
		Long commentId = Long.parseLong(request.getParameter("commId"));
		Session hbSession = DbUtils.startSession();
		try {
			DbUtils.deleteComment(hbSession, commentId);
			hbSession.getTransaction().commit();
			response.sendRedirect("ViewPicture.jsp?image="+imageId);
		} catch (Exception e) {
			if (hbSession != null) {
				hbSession.getTransaction().rollback();
				hbSession.close();
			}
			response.sendRedirect("Error.jsp?msg=comment");
			e.printStackTrace();
		}
	}

}